<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>后台权限管理</title>
		<link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet" />
		<link rel="stylesheet" href="__PUBLIC__/css/global.css" media="all">
		<link href="__PUBLIC__/Font-Awesome/css/font-awesome.css" rel="stylesheet" />
	</head>

	<body>
		<div class="admin-main">
		
			<blockquote class="layui-elem-quote">
				<button  data="0" class="layui-btn layui-btn-small add">
					<i class="layui-icon">&#xe608;</i> 添加后台权限
				</button>
			</blockquote>
			<fieldset class="layui-elem-field">
				<legend>后台权限列表</legend>
				<div class="layui-field-box">
				<table class="layui-table">
					  <thead>
					    <tr>
					      <th>序号</th>
					      <th>权限名称</th>
					      <th>控制器名称</th>
					      <th>方法名称</th>
					      <th>菜单级别</th>
					      <th>管理</th>
					    </tr> 
					  </thead>
					  <tbody>
						<foreach name="auth" key="k" item="vo">
						    <tr>
						      <php>$opt = explode('/',$vo['act_action']);</php>
						      <td>{$k+1}</td>
							  <?php if($vo['act_pid'] != 0){?>
							  <td style=" padding-left: <?php echo 25*$vo['level'] ?>px"><?php echo "|".str_repeat("—",$vo["level"]);?><?php echo $vo['act_name']?></td>
							  <?php }else{ ?>
							  <td>{$vo.act_name}</td>
							  <?php }?>
						      <td><if condition="empty($opt[0])"><else/>{$opt[0]}</if></td>
						      <td><if condition="empty($opt[1])"><else/>{$opt[1]}</if></td>
						      <td>
						      <if condition="$vo['level'] eq 0">一级权限
							  <elseif condition="$vo['level'] eq 1" />二级权限
						      <elseif condition="$vo['level'] eq 2"  />三级权限
						      <else/> 四级权限
						      </if>
						      </td>
						      <td>
						      	<a data="{$vo.act_id}" data-is="{$vo['level']}" class="layui-btn layui-btn-mini add"><i class="layui-icon">&#xe608;</i>添加子权限</a>
								<a data="{$vo.act_id}" class="layui-btn layui-btn-mini layui-btn-normal edit"><i class="layui-icon">&#xe642;</i>编辑</a>
								<if condition="$vo['act_pid'] neq 0">
								<a  data="{$vo.act_id}" class="layui-btn layui-btn-danger layui-btn-mini del"><i class="layui-icon">&#xe640;</i>删除</a>
								</if>
						      </td>
						    </tr>
						</foreach>
					  </tbody>
				</table>
				</div>
			</fieldset>
		</div>
		<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
		<script>
			var $,form;
			layui.use(['layer','form'], function() {
				$ = layui.jquery;
                form = layui.form();
				$('.add').click(function(){
					var id = $(this).attr('data');
					var laravel=$(this).attr('data-is');
					var url = "{:U('System/jurisdictionAdd')}";
					$.get(url,{id:id,isdis:laravel},function(data){
						if(data.status == 'error'){
							layer.msg(data.msg,{icon: 5});
							return;
						}
						layer.open({
							title:'添加权限',
							type: 1,
							skin: 'layui-layer-rim',
							area: ['500px'],
							content: data,
						});
					});
				});
				$('.edit').click(function(){
					var id = $(this).attr('data');
					var url = "{:U('System/jurisdictionEdit')}";
					$.get(url,{id:id},function(data){
						if(data.status == 'error'){
							layer.msg(data.msg,{icon: 5});
							return;
						}
						layer.open({
							title:'编辑权限',
							type: 1,
							skin: 'layui-layer-rim',
							area: ['500px'],
							content: data,
						});
					});
				});
				$('.del').click(function(){
					var id = $(this).attr('data');
					var url = "{:U('System/jurisdictionDelete')}";
					layer.confirm('确定删除吗?', {
						icon: 3,
						skin: 'layer-ext-moon',
						btn: ['确认','取消']
					}, function(){
						$.post(url,{id:id},function(data){
							if(data.status == 'error'){
								layer.msg(data.msg,{icon: 5});
								return;
							}else{
								layer.msg(data.msg, {
									icon: 6,
									time: 2000
								}, function(){
									location.reload();
								});
							}
						});
					});
				});
			});
		</script>
	</body>
</html>